<?php

namespace App\Models\Elasticsearch\Log;

use App\Models\Elasticsearch\Model;

class Cost extends Model
{

    const INDEX_NAME = 't_log_cost';

    /**
     * 获取一条日志【来源ID】
     *
     * @param $sourceId
     * @return array|null
     */
    protected function findBySourceId($sourceId): ?array
    {
        $params = ['body' => ['track_total_hits' => false, 'size' => 1]];
        // 筛选【来源ID】
        $params['body']['query']['bool']['must'][] = [
            'term' => ['source_id' => $sourceId]
        ];
        // 查询数据
        $results = $this->search($params);

        return $results['hits']['hits'][0] ?? null;
    }
}
